package cn.yj.netty.service;

import cn.yj.netty.message.eventshander.AbstractMessageHandler;
import cn.yj.netty.support.test.MessageProtocol;
import cn.yj.netty.common.CommandCode;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 业务具体处理：测试
 *
 * @author 永健
 * @since 2022-02-15 14:27
 */
//@Component(value = "0000")
@Component
public class TestMessageHandler extends AbstractMessageHandler<MessageProtocol> {
    private static final Logger log = LoggerFactory.getLogger(TestMessageHandler.class);

    @Override
    protected void doHandler(MessageProtocol msg) {
        log.info("TestMessageHandler 接收到消息:{}", msg.getBody());
        HashMap<String, Object> stringObjectHashMap = new HashMap<>();
        stringObjectHashMap.put("code", 200);
        stringObjectHashMap.put("msg", "服务端收到消息");
        msg.setBody(JSON.toJSONString(stringObjectHashMap));
        super.response(msg);
    }

    @Override
    public boolean support(MessageProtocol msg) {
        return support(CommandCode.TEST, msg);
    }
}
